package com.onpositive.wiki2.whole.model;

import java.io.File;

import com.onpositive.compactdata.StorableIntMap;
import com.onpositive.wiki2.miner.AbstractWikiPediaVisitor;
import com.onpositive.wiki2.miner.CompositeVisitor;
import com.onpositive.wiki2.miner.Page;
import com.onpositive.wiki2.miner.WikiPediaPass;

public class ItToIndexWriter {

	public static void main(String[] args) {
		File file = new File(Constants.PATH);
		try {
			//final ContentAccess c = new ContentAccess(file.getAbsolutePath());
			
			final StorableIntMap map=new StorableIntMap();
			CompositeVisitor va = new CompositeVisitor();
			va.add(new AbstractWikiPediaVisitor() {

				int a = 0;

				@Override
				protected void onPage(Page page) {
					if (page.id>Integer.MAX_VALUE){
						throw new RuntimeException();
					}
					map.put((int)page.id, a);
					a++;
					if (a % 1000 == 0) {
						System.out.println(a+":"+map.map.size());
					}

				}
			});
			WikiPediaPass.doPass(va);
			map.write(new File(file,"idToIndex.map"));
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
	}
}
